package com.dk.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dk.data.PageBean;
import com.dk.data.Result;
import com.dk.em.ConstantEnum;
import com.dk.entity.TGoods;
import com.dk.entity.TLabel;
import com.dk.entity.TStaging;
import com.dk.mapper.TStagingMapper;
import com.dk.service.ITStagingService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2021-11-02
 */
@RestController
@RequestMapping("/staging")
public class TStagingController {

    @Autowired
    private TStagingMapper stagingMapper;

    @Autowired
    private ITStagingService stagingService;

    @ApiOperation(value = "后台用户明细增加功能")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "paymentTime", value = "付款时长(1为零首付18期, 2为12期, 3为24期, 4为36期)", required = true, paramType = "query"),
            @ApiImplicitParam(name = "staging", value = "是否分期(1 ,分期  2,不分期)", required = true, paramType = "query"),
            @ApiImplicitParam(name = "whetherLoan", value = "是否贷款(1为贷款, 2为不贷款)", required = true, paramType = "query"),
            @ApiImplicitParam(name = "money", value = "车的金额", required = true, paramType = "query"),
            @ApiImplicitParam(name = "loanAmount", value = "贷款金额", required = true, paramType = "query"),
            @ApiImplicitParam(name = "interest", value = "利息百分比()", required = true, paramType = "query"),
            @ApiImplicitParam(name = "actualAmount", value = "实付金额", required = true, paramType = "query"),
            @ApiImplicitParam(name = "adminId", value = "用户id", required = true, paramType = "query"),
            @ApiImplicitParam(name = "mountsPayable", value = "应付金额", required = true, paramType = "query")
    })
    @PostMapping("add")
    public Result add(TStaging staging) {
        staging.setDeleted(0);
        staging.setVersion(1);
        staging.setCreateTime(new Date());
        staging.setUpdateTime(new Date());
        int i = stagingMapper.insert(staging);
        if (i > 0) {
            return Result.bulid(ConstantEnum.SUCCESS).setResult("用户明细增加成功");
        }
        return Result.bulid(ConstantEnum.ERROR).setResult("用户明细增加失败");
    }

    @ApiOperation(value = "后台用户明细修改功能")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户明细表的id", required = true, paramType = "query"),
            @ApiImplicitParam(name = "paymentTime", value = "付款时长(1为零首付18期, 2为12期, 3为24期, 4为36期)", required = true, paramType = "query"),
            @ApiImplicitParam(name = "staging", value = "是否分期(1 ,分期  2,不分期)", required = true, paramType = "query"),
            @ApiImplicitParam(name = "whetherLoan", value = "是否贷款(1为贷款, 2为不贷款)", required = true, paramType = "query"),
            @ApiImplicitParam(name = "money", value = "车的金额", required = true, paramType = "query"),
            @ApiImplicitParam(name = "loanAmount", value = "贷款金额", required = true, paramType = "query"),
            @ApiImplicitParam(name = "interest", value = "利息百分比()", required = true, paramType = "query"),
            @ApiImplicitParam(name = "actualAmount", value = "实付金额", required = true, paramType = "query"),
            @ApiImplicitParam(name = "adminId", value = "用户id", required = true, paramType = "query"),
            @ApiImplicitParam(name = "mountsPayable", value = "应付金额", required = true, paramType = "query")
    })
    @PostMapping("update")
    public Result update(TStaging staging){
        staging.setUpdateTime(new Date());
        int i = stagingMapper.updateById(staging);
        if (i > 0){
            return Result.bulid(ConstantEnum.SUCCESS).setResult("用户明细修改成功");
        }
        return Result.bulid(ConstantEnum.ERROR).setResult("用户明细修改失败");
    }

    @ApiOperation(value = "后台用户明细单条删除功能")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "用户明细表的id",required = true,paramType = "query"),
    })
    @PostMapping("deleteById")
    public Result deleteById(Long id){
        int i = stagingMapper.deleteById(id);
        if (i > 0){
            return Result.bulid(ConstantEnum.SUCCESS).setResult("用户明细单条删除成功");
        }
        return Result.bulid(ConstantEnum.ERROR).setResult("用户明细单条删除失败");
    }

    @ApiOperation(value = "查询后台自营商品表")
    @ApiImplicitParams({
            @ApiImplicitParam(name="num",value = "从第几条开始",required = true,paramType = "query"),
            @ApiImplicitParam(name="size",value = "查询多少条",required = true,paramType = "query")
    })
    @GetMapping("findAllByTStaging")
    public Result findAllByMileageAsc(Integer num,Integer size){
        PageBean pageBean=stagingService.findAllByTStaging(num,size);
        return Result.bulid(ConstantEnum.SUCCESS).setResult(pageBean);
    }
}